﻿namespace instamuz.DataAccess.Overrides
{
    using Domain.Entities;
    using FluentNHibernate.Automapping;
    using FluentNHibernate.Automapping.Alterations;
    using FluentNHibernate.Mapping;

    public class AccountOverride : IAutoMappingOverride<Account>
    {
        public void Override(AutoMapping<Account> mapping)
        {
            mapping
                .HasMany(x => x.Posts)
                .Access.ReadOnlyPropertyThroughCamelCaseField(Prefix.Underscore)
                .Cascade.SaveUpdate()
                .Inverse();

            mapping
                .HasManyToMany(x => x.Followers)
                .Table("FOLLOWERS")
                .ParentKeyColumn("ACCOUNT_ID")
                .ChildKeyColumn("FOLLOWER_ID")
                .Access.ReadOnlyPropertyThroughCamelCaseField(Prefix.Underscore)
                .AsSet();

            mapping
                .HasManyToMany(x => x.Following)
                .Table("FOLLOWING")
                .ParentKeyColumn("ACCOUNT_ID")
                .ChildKeyColumn("FOLLOWING_ID")
                .Access.ReadOnlyPropertyThroughCamelCaseField(Prefix.Underscore)
                .AsSet();
        }
    }
}